package com.kingsalert.kingsalert.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.kingsalert.kingsalert.R;


public class PhotoSelectorDialog extends Dialog {

    private final Runnable takeAPhotoRunnable,fromAlbumRunnable;

    public PhotoSelectorDialog(@NonNull Context context,Runnable takeAPhotoRunnable,Runnable fromAlbumRunnable) {
        super(context);
        this.takeAPhotoRunnable = takeAPhotoRunnable;
        this.fromAlbumRunnable = fromAlbumRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_photo_selector);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        initView();
    }

    @SuppressLint("SetTextI18n")
    private void initView(){

        findViewById(R.id.dps_ib_close).setOnClickListener(v -> dismiss());

        findViewById(R.id.dps_view_takephoto).setOnClickListener(v -> {
            if (takeAPhotoRunnable!=null) takeAPhotoRunnable.run();
            dismiss();
        });

        findViewById(R.id.dps_view_fromalbum).setOnClickListener(v -> {
            if (fromAlbumRunnable!=null) fromAlbumRunnable.run();
            dismiss();
        });

    }
}
